/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acceso.servlet;

import acceso.hibernate.AccesoHibernate;
import acceso.util.Escritor;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.hibernate.StatelessSession;
import wf3.core.Contenedor;
import wf3.core.cnt.GConten;
//import wf3.core.GConten;

/**
 *
 * @author romulogalindo
 */
public class Workgeo extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        response.setContentType("text/html;charset=ISO-8859-1");
        HttpSession SS = request.getSession();
        StatelessSession HS = null;
        Escritor.escribe_frawor("===== Iniciando Workflow-Geo ======");
        
        Contenedor contenedor = null;
        try {
            //System.out.println("1");
            contenedor = new GConten(request, AccesoHibernate.getSessionFactory().openStatelessSession());
            //contenedor = Conten.create_conten(request, AccesoHibernate.getSessionFactory().openStatelessSession());
            request.getSession().setAttribute(contenedor.get_Id_frawor()+"", contenedor);
            response.sendRedirect(request.getContextPath() + "/workflow2/contenedor.jsp?id_frawor="+contenedor.get_Id_frawor());
            //System.out.println("2");
        }catch(Exception ep){
            //System.out.println(ep.getClass());
            /*if(ep instanceof  org.hibernate.HibernateException){
                
            }*/
            if(ep instanceof  org.hibernate.exception.SQLGrammarException){
                //System.out.println("[>]"+((org.hibernate.exception.SQLGrammarException)ep).getMessage());
                //System.out.println("[>]"+((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage());
            }
            System.out.println(">>"+ep.getMessage());
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}